#include "app_fs_load_list.h"
#include <stdint.h>

#ifdef __has_include
    #if __has_include("lvgl.h")
        #ifndef LV_LVGL_H_INCLUDE_SIMPLE
            #define LV_LVGL_H_INCLUDE_SIMPLE
        #endif
    #endif
#endif

#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
    #include "lvgl.h"
#else
    #include "lvgl/lvgl.h"
#endif

#include "esp_heap_caps.h"
#include "esp_heap_caps_init.h"

extern lv_img_dsc_t ui_img_bg_png;
extern lv_img_dsc_t ui_img_fire2_png;
extern lv_img_dsc_t ui_img_fire_png;
extern lv_img_dsc_t ui_img_flash_png;
extern lv_img_dsc_t ui_img_gear_png;
extern lv_img_dsc_t ui_img_heartbeat2_png;
extern lv_img_dsc_t ui_img_heartbeat_png;
extern lv_img_dsc_t ui_img_heart_png;
extern lv_img_dsc_t ui_img_history_png;
extern lv_img_dsc_t ui_img_pd2_png;
extern lv_img_dsc_t ui_img_plus_circle_png;
extern lv_img_dsc_t ui_img_remove_png;
extern lv_img_dsc_t ui_img_running_png;
extern lv_img_dsc_t ui_img_shoe_png;
extern lv_img_dsc_t ui_img_temperature_png;
extern lv_img_dsc_t ui_img_thermometer1_png;
extern lv_img_dsc_t ui_img_thermometer2_png;
extern lv_img_dsc_t ui_img_wave1_png;
extern lv_img_dsc_t ui_img_wave2_png;
extern lv_img_dsc_t ui_img_wifi1_png;
extern lv_img_dsc_t ui_img_wifi2_png;


extern uint8_t *ui_img_bg_png_map;
extern uint8_t *ui_img_fire2_png_map;
extern uint8_t *ui_img_fire_png_map;
extern uint8_t *ui_img_flash_png_map;
extern uint8_t *ui_img_gear_png_map;
extern uint8_t *ui_img_heartbeat2_png_map;
extern uint8_t *ui_img_heartbeat_png_map;
extern uint8_t *ui_img_heart_png_map;
extern uint8_t *ui_img_history_png_map;
extern uint8_t *ui_img_pd2_png_map;
extern uint8_t *ui_img_plus_circle_png_map;
extern uint8_t *ui_img_remove_png_map;
extern uint8_t *ui_img_running_png_map;
extern uint8_t *ui_img_shoe_png_map;
extern uint8_t *ui_img_temperature_png_map;
extern uint8_t *ui_img_thermometer1_png_map;
extern uint8_t *ui_img_thermometer2_png_map;
extern uint8_t *ui_img_wave1_png_map;
extern uint8_t *ui_img_wave2_png_map;
extern uint8_t *ui_img_wifi1_png_map;
extern uint8_t *ui_img_wifi2_png_map;



int app_fs_load_init(void)
{
    lv_fs_file_t f;
	lv_fs_dir_t d;
	lv_fs_res_t res;
	uint32_t resCount;

	ui_img_bg_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_bg_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_bg_png.data = ui_img_bg_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_bg_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_bg_png_map, ui_img_bg_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_fire2_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_fire2_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_fire2_png.data = ui_img_fire2_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_fire2_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_fire2_png_map, ui_img_fire2_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_fire_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_fire_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_fire_png.data = ui_img_fire_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_fire_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_fire_png_map, ui_img_fire_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_flash_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_flash_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_flash_png.data = ui_img_flash_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_flash_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_flash_png_map, ui_img_flash_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_gear_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_gear_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_gear_png.data = ui_img_gear_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_gear_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_gear_png_map, ui_img_gear_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_heartbeat2_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_heartbeat2_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_heartbeat2_png.data = ui_img_heartbeat2_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_heartbeat2_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_heartbeat2_png_map, ui_img_heartbeat2_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_heartbeat_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_heartbeat_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_heartbeat_png.data = ui_img_heartbeat_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_heartbeat_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_heartbeat_png_map, ui_img_heartbeat_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_heart_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_heart_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_heart_png.data = ui_img_heart_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_heart_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_heart_png_map, ui_img_heart_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_history_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_history_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_history_png.data = ui_img_history_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_history_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_history_png_map, ui_img_history_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_pd2_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_pd2_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_pd2_png.data = ui_img_pd2_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_pd2_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_pd2_png_map, ui_img_pd2_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_plus_circle_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_plus_circle_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_plus_circle_png.data = ui_img_plus_circle_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_plus_circle_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_plus_circle_png_map, ui_img_plus_circle_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_remove_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_remove_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_remove_png.data = ui_img_remove_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_remove_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_remove_png_map, ui_img_remove_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_running_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_running_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_running_png.data = ui_img_running_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_running_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_running_png_map, ui_img_running_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_shoe_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_shoe_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_shoe_png.data = ui_img_shoe_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_shoe_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_shoe_png_map, ui_img_shoe_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_temperature_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_temperature_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_temperature_png.data = ui_img_temperature_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_temperature_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_temperature_png_map, ui_img_temperature_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_thermometer1_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_thermometer1_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_thermometer1_png.data = ui_img_thermometer1_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_thermometer1_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_thermometer1_png_map, ui_img_thermometer1_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_thermometer2_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_thermometer2_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_thermometer2_png.data = ui_img_thermometer2_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_thermometer2_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_thermometer2_png_map, ui_img_thermometer2_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_wave1_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_wave1_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_wave1_png.data = ui_img_wave1_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_wave1_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_wave1_png_map, ui_img_wave1_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_wave2_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_wave2_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_wave2_png.data = ui_img_wave2_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_wave2_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_wave2_png_map, ui_img_wave2_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_wifi1_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_wifi1_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_wifi1_png.data = ui_img_wifi1_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_wifi1_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_wifi1_png_map, ui_img_wifi1_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}

	ui_img_wifi2_png_map = (uint8_t*)heap_caps_malloc(sizeof(uint8_t) * ui_img_wifi2_png.data_size, MALLOC_CAP_SPIRAM);
	ui_img_wifi2_png.data = ui_img_wifi2_png_map;
	res = lv_fs_open(&f,"C:/source/ui_img_wifi2_png.bin", LV_FS_MODE_RD);// ֻ����ʽ��һ���ļ�
	if(res == LV_FS_RES_OK) {
		res = lv_fs_read(&f, ui_img_wifi2_png_map, ui_img_wifi2_png.data_size, &resCount);
		if(res != LV_FS_RES_OK) {
			return 2;
		}
		lv_fs_close(&f);
	} else {
		return 1;
	}


    return 0;
}

